﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fixx.Connector;
using Fixx.DTO.Parser;

namespace FixxVS
{
	[Serializable]
	public class FixxVSSettings : IFixxSettings
	{
		private readonly string _username;
        public string Username {
            get { return this._username; } 
        }
        private readonly string _password;
        public string Password
        {
            get { return this._password; }
        }
        private readonly string _host;
        public string Host
        {
            get { return this._host; }
        }
        private readonly int _port;
        public int Port
        {
            get { return this._port; }
        }
		private readonly int _timeOut;
        public int TimeOut
        {
            get { return this._timeOut; }
        }

		public bool IncludeArchivedProjects { get; set; }
		public bool IncludeClosedIssues { get; set; }
		public bool IncludeResolvedIssues { get; set; }
		public bool OnlyIssuesAssignedToMe { get; set; }

		public bool IsUsingPretyDateFormater { get; set; }

		public enum IssueListviewColumnSize
		{
			SizeToCaption = -1,
			SizeToContent = -2
		}

		public enum IssueListviewColumn
		{
			Title,
			Description,
			AssignedTo,
			CreatedBy,
			IssueType,
			Priority,
			Area,
			EstimatedTime,
			AffectedVersion,
			FixForVersion,
			Resolution,
			ResolvedBy,
			ResolvedOn,
			IsClosed,
			ClosedOn,
			DueOn,		
		}

		public TransportLayer TransportLayer { get; private set; }
		public FixxParserFormat FixxParserFormat { get; private set; }
		
		private Dictionary<IssueListviewColumn, IssueListviewColumnSize> _IssueListviewColumnConfig;
		public Dictionary<IssueListviewColumn, IssueListviewColumnSize> IssueListviewColumnConfig 
		{
			get
			{
				if (this._IssueListviewColumnConfig != null)
					return this._IssueListviewColumnConfig;


				//return a default configuration
				return new Dictionary<IssueListviewColumn, IssueListviewColumnSize>()
				{
					{ IssueListviewColumn.Priority, IssueListviewColumnSize.SizeToCaption},
					{ IssueListviewColumn.Area, IssueListviewColumnSize.SizeToCaption},
					{ IssueListviewColumn.IssueType, IssueListviewColumnSize.SizeToCaption},
					{ IssueListviewColumn.AssignedTo, IssueListviewColumnSize.SizeToContent},
					{ IssueListviewColumn.CreatedBy, IssueListviewColumnSize.SizeToContent},
					{ IssueListviewColumn.Title, IssueListviewColumnSize.SizeToContent},
				};
			}
			set
			{
				this._IssueListviewColumnConfig = value;
			}
		}

		public FixxVSSettings(string username, string password, string host, int port)
			: this(username, password, host, port,60000) { }

		public FixxVSSettings(string username, string password, string host, int port, int timeout)
		{
            this._host = host;
            this._password = password;
            this._username = username;
            this._timeOut = timeout;
			this._port = port;
			this.TransportLayer = TransportLayer.XML;
			switch (this.TransportLayer)
			{
				case TransportLayer.JSON:
					this.FixxParserFormat = FixxParserFormat.JSON;
					break;
				default:
					this.FixxParserFormat = FixxParserFormat.XML;
					break;
			}
        
        }
	}
}
